<?php
require_once 'Zend/Controller/Action.php';

class SitemapController extends App_Zend_Controller_Action_Shop
{
	public function productAction()
	{
		$this->getHelper('layout')->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		$itemShow=new CItemShow();
        $itemShow->setType('product');
       	$itemShow->setWhere('1=1');
      
        $myorder='';
        $itemArray=$itemShow->getAllItems();

        header('Content-Type: application/xml');
        
        echo '<?xml version="1.0" encoding="UTF-8"?>';
		echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
        
		foreach ($itemArray as $v) {
			echo '<url>';
    		echo '<loc>';
    		echo MY_URL . '/pd-' . $v['itemid'] . '.html';
    		echo '</loc>';
    		echo '<priority>0.9</priority>';
   			echo '</url>';
		}
		echo '</urlset>';		
	}
	
	public function hotproductAction()
	{
		$this->getHelper('layout')->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		$crawl = new CCrawl();
		
		$keyList = $crawl->fetchAll(array(), 'rand()', 1000);		
		header('Content-Type: application/xml'); 
        echo '<?xml version="1.0" encoding="UTF-8"?>';
		echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
		
		foreach ($keyList as $v) {
			echo '<url>';
    		echo '<loc>';
    		echo MY_URL . '/football_shirt_'.$v->id.'.html';
    		echo '</loc>';
    		echo '<priority>0.7</priority>';
   			echo '</url>';
		}
		
		echo '</urlset>';	
	}
	
	public function categoryAction()
	{
		$this->getHelper('layout')->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		
		$productFl = new CFenlei('product');
        $productFl->order = "en_flname ASC";
        header('Content-Type: application/xml'); 
        $flArray2 = $productFl->getFenleiByPid(92);
        echo '<?xml version="1.0" encoding="UTF-8"?>';
		echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
		
		foreach ($flArray2 as $v) {
			echo '<url>';
    		echo '<loc>';
    		echo MY_URL . '/new-jersey-category-' . $v['flid'] . '-0-1-' . $this->view->encodeName($v['en_flname']) . '.html';
    		echo '</loc>';
    		echo '<priority>0.6</priority>';
   			echo '</url>';
		}
		
		$flArray2 = $productFl->getFenleiByPid(93);
		
		foreach ($flArray2 as $v) {
			echo '<url>';
    		echo '<loc>';
    		echo MY_URL . '/new-jersey-category-' . $v['flid'] . '-0-1-' . $this->view->encodeName($v['en_flname']) . '.html';
    		echo '</loc>';
    		echo '<priority>0.6</priority>';
   			echo '</url>';
		}
		
		echo '</urlset>';		
	}
	
	public function productsAction()
	{
		$this->getHelper('layout')->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		
		$keyModel = new CKeywords();
		
		$keyList = $keyModel->fetchAll(array('product_num>5'), 'rand()', 1000);		
		header('Content-Type: application/xml'); 
        echo '<?xml version="1.0" encoding="UTF-8"?>';
		echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
		
		foreach ($keyList as $v) {
			echo '<url>';
    		echo '<loc>';
    		echo MY_URL . '/product/' . $keyModel->encode($v->keywords) . '_1.html';
    		echo '</loc>';
    		echo '<priority>0.7</priority>';
   			echo '</url>';
		}
		
		echo '</urlset>';		
	}
	
	public function packAction()
	{
		$this->getHelper('layout')->disableLayout();
		$this->getHelper('viewRenderer')->setNoRender();
		$page=$this->_request->getParam('offset',1);
		$myCache = Zend_Registry::get('myCache');
		$itemMap = CCache::getCombinlistItemMap();
		$this->getHelper('Fenlei')->getCategories();
		$itemIdArray = array();
		$i = 0;
		foreach($itemMap as $key=>$value){
			$itemIdArray[$i]=$key;
			$i++;
		}
		$resultIdArray = array();
		$offset = ($page - 1) * 1000;
		for($i=$offset;$i<$offset+1000;$i++){
			$resultIdArray[] = CMd5cmn::combinAction($itemIdArray,$i);
		}
		
		header('Content-Type: application/xml'); 
        echo '<?xml version="1.0" encoding="UTF-8"?>';
		echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">';
		
		foreach ($resultIdArray as $v) {
			echo '<url>';
    		echo '<loc>';
    		echo MY_URL . '/promotion_' . base64_encode($v[0] . '|' . $v[1] . '|' . $v[2] . '|' . $v[3]) . '.html';
    		echo '</loc>';
    		echo '<priority>0.7</priority>';
   			echo '</url>';
		}
		
		echo '</urlset>';		
		
	}
}